//
//  TeachViewController.m
//  PokerPlus
//
//  Created by Lv Changye on 11-8-3.
//  Copyright 2011年 139me. All rights reserved.
//

#import "TeachViewController.h"


@implementation TeachViewController
@synthesize  delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [desk release];
    desk=nil;
    [chatWindow release];
    chatWindow=nil;
    [paiXing release];
    paiXing=nil;
    [p1 release];p1=nil;
    [p2 release];p2=nil;
    [p3 release];p3=nil;
    [p4 release];p4=nil;
    [p5 release];p5=nil;
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"教学桌面.png"]];
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated{
    count=0;
    if (desk==nil) {
        desk=[[UIImageView alloc]initWithFrame:CGRectMake(270,150, 919/2, 575/2)];
    }
    desk.image=[UIImage imageNamed:@"教程桌子1.png"];
    desk.alpha=0.0;
    [self.view addSubview:desk];
    
    UIButton *backButton=[UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame=CGRectMake(880, 115, 117, 43);
    [backButton setImage:[UIImage imageNamed:@"前往大厅.png"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    
    [self chatToNext];
    [super viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
-(void)chatAppear{
    if (next==nil) {
        next=[UIButton buttonWithType:UIButtonTypeCustom];
        next.frame=CGRectMake(263, 81, 40, 40);
        //next.backgroundColor=[UIColor redColor];
        [next setImage:[UIImage imageNamed:@"前进.png"] forState:UIControlStateNormal];
        [next addTarget:self action:@selector(chatToNext) forControlEvents:UIControlEventTouchUpInside];
    }
    [chatWindow addSubview:next];
    
    if (forward==nil) {
        forward=[UIButton buttonWithType:UIButtonTypeCustom];
        forward.frame=CGRectMake(20, 100, 40, 40);
        [forward setImage:[UIImage imageNamed:@"后退.png"] forState:UIControlStateNormal];
        //forward.backgroundColor=[UIColor whiteColor];
        [forward addTarget:self action:@selector(chatToForward) forControlEvents:UIControlEventTouchUpInside];
    }
    [chatWindow addSubview:forward];
    forward.alpha=0.0;
    next.alpha=0.0;
    chatWindow.alpha=0.0;
    [self.view addSubview:chatWindow];
    
    
    if (paiXing==nil) {
        paiXing=[[UIImageView alloc]initWithFrame:CGRectMake(-264, 150, 289, 556)];
        paiXing.image=[UIImage imageNamed:@"牌型组合.png"];
        paiXing.backgroundColor=[UIColor clearColor];
    }
    [self.view addSubview:paiXing];
    paiXing.alpha=0.0;
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    chatWindow.alpha=1.0;
    next.alpha=1.0;
    paiXing.alpha=1.0;
    [UIView commitAnimations];
    

}
//前进至第几步
-(void)chatToNext{
    if (count<10) {
        count++;
    }
    else
        return;
    
    NSLog(@"%d",count);
    switch (count) {
        case 1:{
            
            if (chatWindow==nil) {
                chatWindow=[[UIImageView alloc]init];
                chatWindow.userInteractionEnabled=YES;
            }
            chatWindow.frame=CGRectMake(363, 105, 309, 136);
            chatWindow.image=[UIImage imageNamed:@"第一步.png"];
            next.frame=CGRectMake(263, 81, 40, 40);
            forward.alpha=0.0;
            chatWindow.alpha=0.0;
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            desk.frame=CGRectMake(33,200, 919, 575);
            desk.alpha=1.0;
            [UIView commitAnimations];
            [self performSelector:@selector(chatAppear) withObject:nil afterDelay:1.0];
            break;
            }
        case 2:{
            paiXing.frame=CGRectMake(-264, 150, 289, 556);
            chatWindow.frame=CGRectMake(220, 100, 603, 136);
            chatWindow.image=[UIImage imageNamed:@"第二步.png"];
            next.frame=CGRectMake(550, 78, 40, 40);
            forward.frame=CGRectMake(18, 78, 40, 40);
            forward.alpha=1.0;
            UIImageView *shouPai1=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2, 170, 25, 40)];
            shouPai1.image=[UIImage imageNamed:@"j.png"];
            shouPai1.alpha=0.;
            shouPai1.transform=CGAffineTransformMakeRotation(degreesToRadians(-180));
            [desk addSubview:shouPai1];
            UIImageView *shouPai2=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+10, 170, 25, 40)];
            shouPai2.image=[UIImage imageNamed:@"j2.png"];
            shouPai2.alpha=0.;
            shouPai2.transform=CGAffineTransformMakeRotation(degreesToRadians(-180));
            [desk addSubview:shouPai1];
            [desk addSubview:shouPai2];
            [UIView beginAnimations:@"a" context:nil];
            [UIView setAnimationDelay:0.3];
            [UIView setAnimationDuration:0.4];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            
            shouPai1.frame=CGRectMake(desk.frame.size.width/2+70, 380, 36, 54);
            shouPai1.alpha=1.0;
            shouPai1.transform=CGAffineTransformMakeRotation(degreesToRadians(0));
           
            [UIView commitAnimations];
            [shouPai1 release];
            
            [UIView beginAnimations:@"b" context:nil];
            [UIView setAnimationDelay:0.4];
            [UIView setAnimationDuration:0.4];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            shouPai2.frame=CGRectMake(desk.frame.size.width/2+108, 380, 36, 54);
            shouPai2.alpha=1.0;
            shouPai2.transform=CGAffineTransformMakeRotation(degreesToRadians(0));
            [UIView commitAnimations];
            [shouPai2 release];
            
            UIImageView *gong1=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2, 170, 25, 40)];
            gong1.image=[UIImage imageNamed:@"扑克背面.png"];
            gong1.alpha=0.0;
            gong1.transform=CGAffineTransformMakeRotation(degreesToRadians(-180));
            [desk addSubview:gong1];
            [UIView beginAnimations:@"g1" context:nil];
            [UIView setAnimationDelay:0.6];
            [UIView setAnimationDuration:0.4];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            gong1.frame=CGRectMake(desk.frame.size.width/2-80, 245, 36, 54);
            gong1.alpha=1.0;
            gong1.transform=CGAffineTransformMakeRotation(degreesToRadians(0));
            [UIView commitAnimations];
            [gong1 release];
            UIImageView *gong2=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+5, 170, 25, 40)];
            gong2.image=[UIImage imageNamed:@"扑克背面.png"];
            gong2.alpha=0.0;
            gong2.transform=CGAffineTransformMakeRotation(degreesToRadians(-180));
            [desk addSubview:gong2];
            [UIView beginAnimations:@"g2" context:nil];
            [UIView setAnimationDelay:0.8];
            [UIView setAnimationDuration:0.4];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            gong2.frame=CGRectMake(desk.frame.size.width/2-39, 245, 36, 54);
            gong2.alpha=1.0;
            gong2.transform=CGAffineTransformMakeRotation(degreesToRadians(0));
            [UIView commitAnimations];
            [gong2 release];
            
            UIImageView *gong3=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+10, 170, 25, 40)];
            gong3.image=[UIImage imageNamed:@"扑克背面.png"];
            gong3.alpha=0.0;
            gong3.transform=CGAffineTransformMakeRotation(degreesToRadians(-180));
            [desk addSubview:gong3];
            [UIView beginAnimations:@"g3" context:nil];
            [UIView setAnimationDelay:1];
            [UIView setAnimationDuration:0.4];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            gong3.frame=CGRectMake(desk.frame.size.width/2+2, 245, 36, 54);
            gong3.alpha=1.0;
            gong3.transform=CGAffineTransformMakeRotation(degreesToRadians(0));
            [UIView commitAnimations];
            [gong3 release];
            
            UIImageView *gong4=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+15, 170, 25, 40)];
            gong4.image=[UIImage imageNamed:@"扑克背面.png"];
            gong4.alpha=0.0;
            gong4.transform=CGAffineTransformMakeRotation(degreesToRadians(-180));
            [desk addSubview:gong4];
            [UIView beginAnimations:@"g4" context:nil];
            [UIView setAnimationDelay:1.2];
            [UIView setAnimationDuration:0.4];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            gong4.frame=CGRectMake(desk.frame.size.width/2+43, 245, 36, 54);
            gong4.alpha=1.0;
            gong4.transform=CGAffineTransformMakeRotation(degreesToRadians(0));
            [UIView commitAnimations];
            [gong4 release];
            
            UIImageView *gong5=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+20, 170, 25, 40)];
            gong5.image=[UIImage imageNamed:@"扑克背面.png"];
            gong5.alpha=0.0;
            gong5.transform=CGAffineTransformMakeRotation(degreesToRadians(-180));
            [desk addSubview:gong5];
            [UIView beginAnimations:@"g5" context:nil];
            [UIView setAnimationDelay:1.4];
            [UIView setAnimationDuration:0.4];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            gong5.frame=CGRectMake(desk.frame.size.width/2+84, 245, 36, 54);
            gong5.alpha=1.0;
            gong5.transform=CGAffineTransformMakeRotation(degreesToRadians(0));
            [UIView commitAnimations];
            [gong5 release];
            
            
            UILabel *dipai=[[UILabel alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+113, 343, 50, 30)];
            dipai.text=@"底牌";
            dipai.font=[UIFont systemFontOfSize:16];
            dipai.textColor=[UIColor whiteColor];
            dipai.backgroundColor=[UIColor clearColor];
            [desk addSubview:dipai];
            dipai.alpha=0.0;
            
            
            UIImageView *dipaiKuang=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+63, 370, 86, 70)];
            dipaiKuang.image=[UIImage imageNamed:@"框2.png"];
            dipaiKuang.alpha=0.0;
            [desk addSubview:dipaiKuang];
            
            [UIView animateWithDuration:0.9 delay:1.7 options:UIViewAnimationOptionCurveLinear animations:^{dipai.alpha=1.0;dipaiKuang.alpha=0.0;dipaiKuang.alpha=1.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.9 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{dipaiKuang.alpha=0.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.9 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{dipaiKuang.alpha=0.0;dipaiKuang.alpha=1.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.9 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{dipaiKuang.alpha=0.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.9 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{dipaiKuang.alpha=1.0;} completion:^(BOOL finished){NSLog(@"FFFF");}];}];}];}];}];
            
            [dipai release];
            [dipaiKuang release];
            
            
            UILabel *gongpai=[[UILabel alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+95, 210, 50, 30)];
            gongpai.text=@"公共牌";
            gongpai.font=[UIFont systemFontOfSize:16];
            gongpai.textColor=[UIColor whiteColor];
            gongpai.backgroundColor=[UIColor clearColor];
            [desk addSubview:gongpai];
            gongpai.alpha=0.0;
            
            
            UIImageView *gongpaiKuang=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-100, 235, 243, 72)];
            gongpaiKuang.image=[UIImage imageNamed:@"框1.png"];
            gongpaiKuang.alpha=0.0;
            [desk addSubview:gongpaiKuang];
            
            [UIView animateWithDuration:0.9 delay:6.4 options:UIViewAnimationOptionCurveLinear animations:^{gongpai.alpha=1.0;gongpaiKuang.alpha=1.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.9 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{gongpaiKuang.alpha=0.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.9 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{gongpaiKuang.alpha=0.0;gongpaiKuang.alpha=1.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.9 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{gongpaiKuang.alpha=0.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.9 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{gongpaiKuang.alpha=1.0;} completion:^(BOOL finished){NSLog(@"FFFF");}];}];}];}];}];
            
            [gongpai release];
            [gongpaiKuang release];
            
            
            
            break;
        }
        case 3:{
            for (UIView *view in [desk subviews]) {
                [view removeFromSuperview];
            }
            paiXing.frame=CGRectMake(-264, 150, 289, 556);

            chatWindow.frame=CGRectMake(363, 105, 309, 136);
            chatWindow.image=[UIImage imageNamed:@"第三步.png"];
            next.frame=CGRectMake(269, 85, 40, 40);
            forward.frame=CGRectMake(1, 84, 40, 40);
            
            
            UIImageView *shouPai1=[[UIImageView alloc]init];
            shouPai1.image=[UIImage imageNamed:@"j.png"];
            [desk addSubview:shouPai1];
            UIImageView *shouPai2=[[UIImageView alloc]init];
            shouPai2.image=[UIImage imageNamed:@"j2.png"];
            [desk addSubview:shouPai1];
            [desk addSubview:shouPai2];
            shouPai1.frame=CGRectMake(desk.frame.size.width/2+70, 380, 36, 54);
            shouPai1.alpha=1.0;
            [shouPai1 release];
          
            shouPai2.frame=CGRectMake(desk.frame.size.width/2+108, 380, 36, 54);
            shouPai2.alpha=1.0;
            [shouPai2 release];
            
            UIImageView *gong1=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-80, 245, 36, 54)];
            gong1.image=[UIImage imageNamed:@"扑克背面.png"];
            [desk addSubview:gong1];
            gong1.alpha=1.0;
        
            [gong1 release];
            UIImageView *gong2=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-39, 245, 36, 54)];
            gong2.image=[UIImage imageNamed:@"扑克背面.png"];
            [desk addSubview:gong2];
            gong2.alpha=1.0;
            [gong2 release];
            
            UIImageView *gong3=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+2, 245, 36, 54)];
            gong3.image=[UIImage imageNamed:@"扑克背面.png"];
            [desk addSubview:gong3];
            gong3.alpha=1.0;
            [gong3 release];
            
            UIImageView *gong4=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+43, 245, 36, 54)];
            gong4.image=[UIImage imageNamed:@"扑克背面.png"];
            [desk addSubview:gong4];
            gong4.alpha=1.0;
            [gong4 release];
            
            UIImageView *gong5=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+84, 245, 36, 54)];
            gong5.image=[UIImage imageNamed:@"扑克背面.png"];
            [desk addSubview:gong5];
            gong5.alpha=1.0;
            [gong5 release];
            
            
            UILabel *dipai=[[UILabel alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+113, 343, 50, 30)];
            dipai.text=@"底牌";
            dipai.font=[UIFont systemFontOfSize:16];
            dipai.textColor=[UIColor whiteColor];
            dipai.backgroundColor=[UIColor clearColor];
            [desk addSubview:dipai];
            dipai.alpha=1.0;
            [dipai release];
            
            UIImageView *dipaiKuang=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+63, 370, 86, 70)];
            dipaiKuang.image=[UIImage imageNamed:@"框2.png"];
            dipaiKuang.alpha=1.0;
            [desk addSubview:dipaiKuang];
            [dipaiKuang release];
            
            
            UILabel *gongpai=[[UILabel alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+95, 210, 50, 30)];
            gongpai.text=@"公共牌";
            gongpai.font=[UIFont systemFontOfSize:16];
            gongpai.textColor=[UIColor whiteColor];
            gongpai.backgroundColor=[UIColor clearColor];
            [desk addSubview:gongpai];
            gongpai.alpha=1.0;
            [gongpai release];
            
            UIImageView *gongpaiKuang=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-100, 235, 243, 72)];
            gongpaiKuang.image=[UIImage imageNamed:@"框1.png"];
            gongpaiKuang.alpha=1.0;
            [desk addSubview:gongpaiKuang];
            [gongpaiKuang release];
            
            
            [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{paiXing.frame=CGRectMake(0, 150, 289, 556);} completion:^(BOOL finished){NSLog(@"FFFF");}];
            
            UIImageView *shuxian=[[UIImageView alloc]initWithFrame:CGRectMake(552, 308, 2, 62)];
            shuxian.image=[UIImage imageNamed:@"竖线.png"];
            shuxian.alpha=0.0;
            [desk addSubview:shuxian];
            [UIView animateWithDuration:0.6 delay:1.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{shuxian.alpha=1.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.6 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{shuxian.alpha=0.0;} completion:^(BOOL finished){[UIView animateWithDuration:0.6 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{shuxian.alpha=1.0;} completion:^(BOOL finished){NSLog(@"FFFF");}];}];}];
            
            [shuxian release];
            
            
            
            UIImageView *hengxian=[[UIImageView alloc]initWithFrame:CGRectMake(554, 338, 94, 2)];
            hengxian.image=[UIImage imageNamed:@"横线.png"];
            hengxian.alpha=0.0;
            [desk addSubview:hengxian];
            
            UILabel *shoupaiLabel=[[UILabel alloc]initWithFrame:CGRectMake(615, 308, 50, 30)];
            shoupaiLabel.text=@"手牌";
            shoupaiLabel.textColor=[UIColor whiteColor];
            shoupaiLabel.backgroundColor=[UIColor clearColor];
            shoupaiLabel.alpha=0.0;
            [desk addSubview:shoupaiLabel];
            [UIView animateWithDuration:0.6 delay:3.8 options:UIViewAnimationOptionCurveEaseInOut animations:^{hengxian.alpha=1.0;shoupaiLabel.alpha=1.0;} completion:^(BOOL finished){NSLog(@"FFFF");}];
            
            [hengxian release];
            [shoupaiLabel release];
            break;
        }
        case 4:{
            
            chatWindow.frame=CGRectMake(220, 100, 603, 136);
            chatWindow.image=[UIImage imageNamed:@"第四步.png"];
            next.frame=CGRectMake(550, 78, 40, 40);
            forward.frame=CGRectMake(18, 78, 40, 40);
            forward.alpha=1.0;
            [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                paiXing.frame=CGRectMake(-264, 150, 289, 556);
            
                for (UIView *view in[desk subviews]) {
                    [view removeFromSuperview];
                }
                
               
            
            } completion:^(BOOL finished){NSLog(@"FFFF");}];
            

            break;
        }
        case 5:{
            chatWindow.frame=CGRectMake(220, 100, 603, 136);
            chatWindow.image=[UIImage imageNamed:@"第五步.png"];
            next.frame=CGRectMake(550, 78, 40, 40);
            forward.frame=CGRectMake(17, 78, 40, 40);
            
            break;
        }
        case 6:{
            
            chatWindow.frame=CGRectMake(220, 100, 603, 136);
            chatWindow.image=[UIImage imageNamed:@"第六步.png"];
            next.frame=CGRectMake(550, 78, 40, 40);
            forward.frame=CGRectMake(18, 78, 40, 40);
            
            break;
        }
        case 7:{
            desk.image=[UIImage imageNamed:@"教程桌子1.png"];
            desk.frame=CGRectMake(33,200, 919, 575);
            chatWindow.frame=CGRectMake(363, 105, 309, 136);
            chatWindow.image=[UIImage imageNamed:@"第七步.png"];
            next.frame=CGRectMake(264, 82, 40, 40);
            forward.frame=CGRectMake(4, 81, 40, 40);
            
            UIImageView *zhuo2=[[UIImageView alloc]initWithFrame:CGRectMake(-14, -20, 986, 595)];
            zhuo2.image=[UIImage imageNamed:@"教程桌子2.png"];
            [desk addSubview:zhuo2];
            zhuo2.alpha=0.0;
            [UIView animateWithDuration:1.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                zhuo2.alpha=1.0;
            } completion:^(BOOL finished){}];
            [zhuo2 release];
            break;
        }
        case 8:{
            chatWindow.frame=CGRectMake(363, 105, 309, 136);
            chatWindow.image=[UIImage imageNamed:@"第八步.png"];
            next.frame=CGRectMake(264, 82, 40, 40);
            forward.frame=CGRectMake(7, 80, 40, 40);
            
            
            desk.image=[UIImage imageNamed:@"教程桌子2.png"];
            desk.frame=CGRectMake(19, 180, 986, 595);
            for (UIView *view in [desk subviews]) {
                [view removeFromSuperview];
            }
            
            if (p1==nil) {
                p1=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-100, 265, 36, 54)];
            }
            for (UIView *v in [p1 subviews]) {
                [v removeFromSuperview];
            }
            [desk addSubview:p1];
            
            if (p2==nil) {
                p2=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-60, 265, 36, 54)];
            }
            for (UIView *v in [p2 subviews]) {
                [v removeFromSuperview];
            }
            [desk addSubview:p2];
            
            if (p3==nil) {
                p3=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-20, 265, 36, 54)];
            }
            for (UIView *v in [p3 subviews]) {
                [v removeFromSuperview];
            }
            [desk addSubview:p3];
        
            [self performSelector:@selector(addP3) withObject:nil afterDelay:0.0];
            
            
            UIImageView *gongpaiKuang=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-105, 258, 127, 67)];
            gongpaiKuang.image=[UIImage imageNamed:@"框1.png"];
            gongpaiKuang.alpha=0.0;
            [desk addSubview:gongpaiKuang];
            UILabel *fanpai=[[UILabel alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-105, 227, 50, 30)];
            fanpai.text=@"翻牌";
            fanpai.backgroundColor=[UIColor clearColor];
            fanpai.textColor=[UIColor whiteColor];
            [desk addSubview:fanpai];
            fanpai.alpha=0.0;
            
            
            [UIView animateWithDuration:1.0 delay:1.5 options:UIViewAnimationOptionCurveLinear  animations:^{gongpaiKuang.alpha=1.0;fanpai.alpha=1.0;} completion:^(BOOL finished){}];
            [fanpai release];
            [gongpaiKuang release];
            break;
        }
        case 9:{
            chatWindow.frame=CGRectMake(363, 105, 309, 136);
            chatWindow.image=[UIImage imageNamed:@"第九步.png"];
            [next setImage:[UIImage imageNamed:@"前进.png"] forState:UIControlStateNormal];
            [next removeTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
            [next addTarget:self action:@selector(chatToNext) forControlEvents:UIControlEventTouchUpInside];
            next.frame=CGRectMake(264, 82, 40, 40);
            forward.frame=CGRectMake(9, 80, 40, 40);
            
            for (UIView *view in [desk subviews]) {
                [view removeFromSuperview];
            }
            
            UIImageView *q1=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-100, 265, 36, 54)];
            q1.image=[UIImage imageNamed:@"1.png"];
            UIImageView *q2=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-60, 265, 36, 54)];
            q2.image=[UIImage imageNamed:@"q.png"];
            UIImageView *q3=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-20, 265, 36, 54)];
            q3.image=[UIImage imageNamed:@"10.png"];
            
            [desk addSubview:q1];
            [desk addSubview:q2];
            [desk addSubview:q3];
            [q1 release];
            [q2 release];
            [q3 release];
            
            if (p4==nil) {
                p4=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+20, 265, 36, 54)];
            }
            for (UIView *v in [p4 subviews]) {
                [v removeFromSuperview];
            }
            [desk addSubview:p4];
            [self performSelector:@selector(addP4) withObject:nil afterDelay:0.3];
            
            UIImageView *gongpaiKuang=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+17, 259, 42, 65)];
            gongpaiKuang.image=[UIImage imageNamed:@"框2.png"];
            gongpaiKuang.alpha=0.0;
            [desk addSubview:gongpaiKuang];
            UILabel *fanpai=[[UILabel alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+17, 230, 40, 30)];
            fanpai.text=@"转牌";
            fanpai.font=[UIFont systemFontOfSize:15];
            fanpai.backgroundColor=[UIColor clearColor];
            fanpai.textColor=[UIColor whiteColor];
            [desk addSubview:fanpai];
            fanpai.alpha=0.0;
            
            
            [UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveLinear  animations:^{gongpaiKuang.alpha=1.0;fanpai.alpha=1.0;} completion:^(BOOL finished){}];
            [fanpai release];
            [gongpaiKuang release];

            break;
        }
        case 10:{
            chatWindow.frame=CGRectMake(363, 105, 309, 136);
            chatWindow.image=[UIImage imageNamed:@"第十步.png"];
            [next setImage:[UIImage imageNamed:@"差号.png"] forState:UIControlStateNormal];
            [next removeTarget:self action:@selector(chatToNext) forControlEvents:UIControlEventTouchUpInside];
            [next addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
            next.frame=CGRectMake(266, 82, 40, 40);
            forward.frame=CGRectMake(7, 81, 40, 40);
            
            for (UIView *view in [desk subviews]) {
                [view removeFromSuperview];
            }
            
            UIImageView *q1=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-100, 265, 36, 54)];
            q1.image=[UIImage imageNamed:@"1.png"];
            UIImageView *q2=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-60, 265, 36, 54)];
            q2.image=[UIImage imageNamed:@"q.png"];
            UIImageView *q3=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2-20, 265, 36, 54)];
            q3.image=[UIImage imageNamed:@"10.png"];
            UIImageView *q4=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+20, 265, 36, 54)];
            q4.image=[UIImage imageNamed:@"j.png"];
            
            [desk addSubview:q1];
            [desk addSubview:q2];
            [desk addSubview:q3];
            [desk addSubview:q4];
            [q1 release];
            [q2 release];
            [q3 release];
            [q4 release];
            
            if (p5==nil) {
                p5=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+60, 265, 36, 54)];
            }
            for (UIView *v in [p5 subviews]) {
                [v removeFromSuperview];
            }
            [desk addSubview:p5];
            [self performSelector:@selector(addP5) withObject:nil afterDelay:0.3];
            
            UIImageView *gongpaiKuang=[[UIImageView alloc]initWithFrame:CGRectMake(desk.frame.size.width/2+57, 259, 42, 65)];
            gongpaiKuang.image=[UIImage imageNamed:@"框2.png"];
            gongpaiKuang.alpha=0.0;
            [desk addSubview:gongpaiKuang];
            [UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveLinear  animations:^{gongpaiKuang.alpha=1.0;} completion:^(BOOL finished){}];
            [gongpaiKuang release];
            
            break;
        }
        default:
            break;
    }
    
    

    
    
}

-(void)addP3{
    //翻牌效果

    UIImageView *q1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 36, 54)];
    q1.image=[UIImage imageNamed:@"1.png"];
    UIImageView *q2=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 36, 54)];
    q2.image=[UIImage imageNamed:@"q.png"];
    
    UIImageView *q3=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 36, 54)];
    q3.image=[UIImage imageNamed:@"10.png"];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:p1 cache:NO];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0.0];
    [p1 addSubview:q1];
    [UIView commitAnimations];
    [q1 release];
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:p2 cache:NO];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0.3];
    [p2 addSubview:q2];
    [UIView commitAnimations];
    [q2 release];
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:p3 cache:NO];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0.6];
    [p3 addSubview:q3];
    [UIView commitAnimations];
    [q3 release];
    
}
-(void)addP4{
    UIImageView *q4=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 36, 54)];
    q4.image=[UIImage imageNamed:@"j.png"];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:p4 cache:NO];
    [UIView setAnimationDuration:0.5];
    [p4 addSubview:q4];
    [UIView commitAnimations];
    [q4 release];
    
}
-(void)addP5{
    UIImageView *q5=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 36, 54)];
    q5.image=[UIImage imageNamed:@"3.png"];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:p5 cache:NO];
    [UIView setAnimationDuration:0.5];
    [p5 addSubview:q5];
    [UIView commitAnimations];
    [q5 release];
}
-(void)chatToForward{
    if (count<=1) {
        return;
    }
    for (UIView *view in [desk subviews]) {
        [view removeFromSuperview];
    }
    
    count=count-2;
    [self chatToNext];
    
}
-(void)back:(id)sender{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    [forward removeFromSuperview];
    [next removeFromSuperview];
    [chatWindow removeFromSuperview];
    for (UIView *view in [desk subviews]) {
        [view removeFromSuperview];
    }
    desk.frame=CGRectMake(270,150, 919/2, 575/2);
    desk.alpha=0.0;
    self.view.alpha=0.0;
    [sender removeFromSuperview];
    [UIView commitAnimations];
    [delegate bottomAppear];
    [self performSelector:@selector(remove) withObject:nil afterDelay:1.0];
}
-(void)remove{

    [desk removeFromSuperview];
    [paiXing removeFromSuperview];
    [self.view removeFromSuperview];
    [self release];
}
- (void)viewDidUnload
{
    desk=nil;
    chatWindow=nil;
    paiXing=nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
